import json
from pprint import pprint

from mysql_pool import MySQLPool
from utils import JsonCustomEncoder


if __name__ == '__main__':
    with MySQLPool() as db:
        sql_str = "select * from student"
        res = db.cursor.execute(sql_str)
        print("res: ", res)
        res_datas = db.cursor.fetchall()
        print("res_datas: ")
        pprint(res_datas)
        # 业务需求：需要将每一条记录转换成json字符串
        for curr_dic in res_datas:
            # print("type_curr_dic: ", type(curr_dic))
            # 字典转换为str
            curr_dic_str = json.dumps(curr_dic,cls=JsonCustomEncoder)
            print("2: ", curr_dic_str, type(curr_dic_str))